<template>
  <el-card>
    <el-button
      @click="$router.push('/category/add')"
      type="primary"
      icon="el-icon-circle-plus-outline"
      >新增</el-button
    >
    <el-divider />
    <el-table
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column
        prop="id"
        label="ID"
        sortable
        min-width="80"
      ></el-table-column>
      <el-table-column
        prop="catename"
        label="分类名称"
        min-width="180"
      ></el-table-column>
      <el-table-column prop="img" label="分类图片" min-width="180">
        <template v-slot="scope">
          <img
            :src="$imgBaseURL + scope.row.img"
            alt=""
            style="height: 80px"
          />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" min-width="180">
        <template v-slot="scope">
          <el-tag type="success" v-if="scope.row.status === 1">正常</el-tag>
          <el-tag type="danger" v-else>禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="180">
        <template v-slot="$props">
          <el-button
          @click="$router.push('/category/'+$props.row.id)"
            type="success"
            circle
            size="mini"
            icon="el-icon-edit"
          ></el-button>
          <el-button
          @click="del($props.row.id)"
            type="danger"
            circle
            size="mini"
            icon="el-icon-delete"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
import { getCateList } from "../../request/category";
export default {
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.getCateList();
  },
  methods: {
    del(id){
      this.$confirm(async()=>{
        const res=await this.$http.post("/api/catedelete",{id})
        if(res.code==200){
          this.$success(res.msg)
          this.getCateList()
        }
      })

    },
    async getCateList() {
      const list = await getCateList();
      if (list) {
        //  更新数据
        this.list = list;
      }
    },
  },
};
</script>

<style>
</style>